package com.luyuan.crm.sale.web;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.luyuan.crm.member.model.Customer;
import com.luyuan.crm.product.model.ProductType;
import com.luyuan.crm.sale.model.OrderType;
import com.ruijie.blueprint.spring.context.ApplicationContextHolder;
import com.ruijie.web.jsf.action.BaseAction;
import com.ruijie.web.jsf.action.WizardAccessor;

@Component("addOrderAction")
@Scope("view")
public class AddOrderAction extends BaseAction {

    private OrderType orderType;

    private ProductType productType;

    private Customer customer = new Customer();

    public String startWizard() {
        if (customer == null) {
            addGlobalI18nMessage("请选择购买的客户！");

            return null;
        }

        WizardAccessor wizardAccessor = (WizardAccessor) ApplicationContextHolder.getApplicationContext().getBean(
                "wizardAccessor");

        setRequestAttribute("orderType", orderType, true);
        setRequestAttribute("customer", customer, true);
        setRequestAttribute("productType", productType, true);
        if (orderType == OrderType.SINGLE_PRODUCT) {
            return wizardAccessor.start("singleOrderWizard", "add");
        }
        else {
            return wizardAccessor.start("orderWizard", "add");

        }
    }

    public OrderType getOrderType() {
        return orderType;
    }

    public void setOrderType(OrderType orderType) {
        this.orderType = orderType;
    }

    public ProductType getProductType() {
        return productType;
    }

    public void setProductType(ProductType productType) {
        this.productType = productType;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
}
